namespace RCA_HASH_SALT_EMPTY {
﻿#include <openssl/evp.h>

int  main(int  argc, char* argv[])
{
	const  EVP_CIPHER* cipher;
	const  EVP_MD* digest = NULL;
	unsigned  char  key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
	const  unsigned  char  * salt = "";
	int  i;

	OpenSSL_add_all_algorithms();

	cipher = EVP_get_cipherbyname("aes-256-cbc");
	if  (!cipher)  return   - 1;

	digest = EVP_get_digestbyname("md5");
	if  (!digest)  return   - 1;

	if  (!EVP_BytesToKey(cipher, digest, salt,
		(unsigned  char  *)argv[1], strlen(argv[1]),
		1, key, iv))  return   - 3;

	printf("Key: ");  for (i = 0; i < cipher->key_len; ++i)printf("%02x", key[i]);  printf("\n");
	printf("IV: ");  for (i = 0; i < cipher->iv_len; ++i)  printf("%02x", iv[i]);  printf("\n");

	return  0;
}





#include <openssl/pkcs12.h>

int main(int argc, char* argv[])
{
	const EVP_MD* digest = NULL;
	unsigned char key[EVP_MAX_KEY_LENGTH];
	const unsigned char* salt;
	int i;

	OpenSSL_add_all_algorithms();

	digest = EVP_get_digestbyname("md5");
	if (!digest) return -1;

	if (!PKCS5_PBKDF2_HMAC(argv[1], strlen(argv[1]),
		NULL, 0, -1,
		digest, EVP_MAX_KEY_LENGTH, key))
		return -2;

	printf("Key: "); for (i = 0; i < EVP_MAX_KEY_LENGTH; ++i) printf("%02x", key[i]); printf("\n");

	return 0;
}







#include <openssl/evp.h>
int main(int argc, char* argv[])
{
	const EVP_CIPHER* cipher;
	const EVP_MD* digest = NULL;
	unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
	const unsigned char* default_salt = "7h%ms(81klm3&wer#2";
	const unsigned char* salt;
	int i;

	OpenSSL_add_all_algorithms();

	cipher = EVP_get_cipherbyname("aes-256-cbc");
	if (!cipher) return -1;

	digest = EVP_get_digestbyname("md5");
	if (!digest) return -1;

	if (argc > 2)
		salt = argv[2];
	else
		salt = default_salt;

	if (!EVP_BytesToKey(cipher, digest, salt,
		(unsigned char*)argv[1], strlen(argv[1]),
		1, key, iv)) return -3;

	printf("Key: "); for (i = 0; i < cipher->key_len; ++i) printf("%02x", key[i]); printf("\n");
	printf("IV: ");  for (i = 0; i < cipher->iv_len; ++i) printf("%02x", iv[i]); printf("\n");

	return 0;

}







#include <openssl/pkcs12.h>

int main(int argc, char* argv[])
{
	const EVP_MD* digest = NULL;
	unsigned char key[EVP_MAX_KEY_LENGTH];
	const unsigned char* default_salt = "7h%ms(81klm3&wer#2";
	const unsigned char* salt;
	int i;

	OpenSSL_add_all_algorithms();

	digest = EVP_get_digestbyname("md5");
	if (!digest) return -1;

	if (argc > 2)
		salt = argv[2];
	else
		salt = default_salt;

	if (!PKCS5_PBKDF2_HMAC(argv[1], strlen(argv[1]),
		salt, strlen(salt), -1,
		digest, EVP_MAX_KEY_LENGTH, key))
		return -2;

	printf("Key: "); for (i = 0; i < EVP_MAX_KEY_LENGTH; ++i) printf("%02x", key[i]); printf("\n");

	return 0;
}
}}